package com.eight.travel.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.travel.dao.StoreComMapper;
import com.eight.travel.dao.UserMapper;
import com.eight.travel.pojo.StoreCom;
import com.eight.travel.service.StoreComService;
import com.eight.travel.utils.BaseResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StoreComServiceImpl extends ServiceImpl<StoreComMapper, StoreCom> implements StoreComService {

    @Resource
    StoreComMapper storeComMapper;
    @Resource
    UserMapper userMapper;
    @Override
    public BaseResp addStoreCom(StoreCom storeCom) {
        int res = storeComMapper.addStoreCom(storeCom);
        if(res == 1){
            return new BaseResp().SUCCESS2("评论成功");
        }
        return new BaseResp().FAIL("评论失败");
    }

    @Override
    public BaseResp deleteStoreCom(Integer scid) {
        int res = storeComMapper.deleteById(scid);
        if(res == 1){
            return new BaseResp().SUCCESS2("删除评论成功");
        }
        return new BaseResp().FAIL("删除评论失败");
    }

    @Override
    public BaseResp updateStoreCom(StoreCom storeCom) {
        int res = storeComMapper.updateStoreCom(storeCom);
        if(res == 1){
            return new BaseResp().SUCCESS2("修改评论成功");
        }
        return new BaseResp().FAIL("修改评论失败");
    }

    @Override
    public BaseResp selectAll(Integer sid) {
        List<StoreCom> storeComs = storeComMapper.selectAll(sid);
        int i = storeComMapper.selectRow();
        if(storeComs != null){
            return new BaseResp().SUCCESS("查询成功", storeComs, i);
        }
        return new BaseResp().FAIL("查询失败");
    }

}
